<!--
 * @Author: your name
 * @Date: 2022-01-17 22:08:12
 * @LastEditTime: 2022-02-18 19:55:37
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue-element-admin\src\views\crm\Linkman.vue
-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-button
        type="primary"
        icon="el-icon-circle-plus-outline"
        @click="addShow()"
        >添加联系人</el-button
      >
    </div>

    <TableGeneral
      ref="tableGeneral"
      :labelWidth="'150px'"
      :tableData="tableData"
      :tableColumn="tableColumn"
      :loading="tableLoading"
      :tableConfig="{ stripe: true }"
      :multiSelect="multiSelect"
      :allSelList="linkmanSelList"
      @refresh="linkmanListLoad"
      @search="search"
    >
      <div slot="nickName" slot-scope="{ scopeRow }">
        <span>{{
          `${scopeRow.nickName}${
            scopeRow.realName ? "(" + scopeRow.realName + ")" : ""
          }`
        }}</span>
      </div>
      <div slot="crm_customer_id" slot-scope="{ scopeRow }">
        <div
          v-if="scopeRow.crm_customer_id"
          style="display: flex; flex-wrap: wrap"
        >
          <el-tag
            v-for="(item, index) in scopeRow.crm_customer_id.split(',')"
            :key="index"
            style="margin-left: 5px"
            >{{ item }}</el-tag
          >
        </div>
      </div>
      <div slot="customer_company_name" slot-scope="{ scopeRow }">
        <div
          v-if="scopeRow.customer_company_name"
          style="display: flex; flex-wrap: wrap"
        >
          <el-tag
            v-for="(item, index) in scopeRow.customer_company_name.split(',')"
            :key="index"
            style="margin-left: 5px"
            >{{ item }}</el-tag
          >
        </div>
      </div>
      <div slot="sex" slot-scope="{ scopeRow }">
        <span v-show="scopeRow.sex == 1">男</span>
        <span v-show="scopeRow.sex == 0">女</span>
      </div>

      <div slot="operation" slot-scope="{ scopeRow }">
        <el-button type="text" size="small" @click="edit(scopeRow)">
          编辑
        </el-button>

        <el-button type="text" size="small" @click="attachmentFunc(scopeRow)">
          附件
        </el-button>

        <el-button type="text" size="small" @click="followUp(scopeRow.id)">
          跟进情况
        </el-button>
        <!-- <template> -->

        <el-popconfirm title="确定要删除吗" @confirm="delOne(scopeRow.id)">
          <!-- <div> -->
          <el-button
            slot="reference"
            type="text"
            size="small"
            style="margin-left: 10px"
            >删除</el-button
          >
        </el-popconfirm>
      </div>
    </TableGeneral>

    <div class="pagination">
      <el-pagination
        background
        layout="sizes,total,prev, pager, next"
        :page-size="config.pageSize"
        :page-sizes="[10, 20, 50, 100]"
        @size-change="sizeChange"
        :total="tableCount"
        @current-change="currentChange"
      >
      </el-pagination>
    </div>
    <!-- 添加联系人 -->
    <el-dialog
      append-to-body
      :title="`${edit_id ? '编辑' : '添加'}联系人`"
      :visible.sync="dialogFormVisible"
      @closed="closed"
      top="10vh"
    >
      <div class="dialogCenter" style="height: 60vh">
        <el-form
          :model="form"
          ref="form"
          :rules="rules"
          v-loading="formLoading"
        >
          <el-form-item label="姓名" :label-width="formLabelWidth" prop="name">
            <div style="display: flex">
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="flex: 1"
              ></el-input>
              <div style="width: 100px; margin-left: 20px">
                <el-select v-model="form.sex" placeholder="性别">
                  <el-option label="男" value="1"></el-option>
                  <el-option label="女" value="0"></el-option>
                </el-select>
              </div>
            </div>
          </el-form-item>
          <el-form-item
            label="公司名称"
            :label-width="formLabelWidth"
            prop="company_name"
          >
            <div style="display: flex">
              <el-input
                v-model="form.company_name"
                autocomplete="off"
              ></el-input>
              <el-input
                v-model="form.dutuies"
                autocomplete="off"
                style="margin-left: 20px"
              >
                <template slot="prepend">职务</template>
              </el-input>
            </div>
          </el-form-item>

          <el-form-item
            label="所属客户"
            :label-width="formLabelWidth"
            v-loading="customer.loading || customer.customerLinkmanIdLoading"
          >
            <el-select
              v-model="customer.customerSelected"
              filterable
              multiple
              collapse-tags
              placeholder="请选择"
              style="width: 500px"
            >
              <el-option
                v-for="(item, index) in customer.customersChoose"
                :key="index"
                :label="item.company_name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>

          <!-- <el-form-item
            label="职务"
            :label-width="formLabelWidth"
            prop="dutuies"
          >
            <el-input v-model="form.dutuies" autocomplete="off"></el-input>
          </el-form-item> -->
          <el-form-item label="所属部门" :label-width="formLabelWidth">
            <TreeSelct
              :props="{ value: 'id', label: 'name', children: 'children' }"
              :options="treeData"
              :accordion="true"
              :clearable="true"
              :value="division_id.toString()"
              :key="'TreeSelct' + division_id"
              ref="treeSelct"
              v-if="!treeDataLoading"
            />
          </el-form-item>
          <div
            :style="{
              display: 'flex',
              'justify-content': 'flex-end',
              'padding-left': formLabelWidth,
            }"
          >
            <div :style="{ width: '100%' }">
              <el-collapse style="flex: 1" v-model="collapseValue">
                <el-collapse-item name="1">
                  <template slot="title">
                    联系电话<el-badge
                      :value="phoneData.length"
                      style="margin-left: 5px"
                    ></el-badge>
                  </template>
                  <div :key="phoneData.key">
                    <ChangeableTable
                      :mapping="{ fileName: 'filePath' }"
                      :tableColumn="phoneColumn"
                      :addTitle="`添加电话`"
                      :dataProps="phoneData.defaultData"
                      ref="phone"
                      style="margin-top: 20px"
                      @lengthChange="(length) => (phoneData.length = length)"
                      :loading="phoneData.loading"
                    >
                    </ChangeableTable>
                  </div>
                </el-collapse-item>
                <el-collapse-item name="2">
                  <template slot="title">
                    微信号<el-badge
                      :value="wechatData.length"
                      style="margin-left: 5px"
                    ></el-badge>
                  </template>
                  <div :key="wechatData.key">
                    <ChangeableTable
                      :mapping="{ fileName: 'filePath' }"
                      :tableColumn="wechatColumn"
                      :addTitle="`添加微信号`"
                      :dataProps="wechatData.defaultData"
                      ref="wechat"
                      style="margin-top: 20px"
                      :loading="wechatData.loading"
                      @lengthChange="(length) => (wechatData.length = length)"
                    >
                    </ChangeableTable>
                  </div>
                </el-collapse-item>
              </el-collapse>
            </div>
          </div>

          <!-- <el-form-item
            label="联系电话"
            :label-width="formLabelWidth"
          >
            
          </el-form-item>

          <el-form-item
            label="微信号"
            :label-width="formLabelWidth"
          >
            
          </el-form-item> -->

          <el-form-item label="联系人所有人" :label-width="formLabelWidth">
            {{
              `${linkmanBelong.nickName}${
                linkmanBelong.realName ? "(" + linkmanBelong.realName + ")" : ""
              }`
            }}
          </el-form-item>

          <el-form-item
            label="固定电话"
            :label-width="formLabelWidth"
            prop="phone"
          >
            <el-input v-model="form.phone" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item label="邮箱" :label-width="formLabelWidth" prop="email">
            <el-input v-model="form.email" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item
            label="地址"
            :label-width="formLabelWidth"
            prop="address"
          >
            <el-input v-model="form.address" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item
            label="邮编"
            :label-width="formLabelWidth"
            prop="zipCode"
          >
            <el-input v-model="form.zipCode" autocomplete="off"></el-input>
          </el-form-item>

          <el-form-item
            label="省份"
            :label-width="formLabelWidth"
            prop="provinces"
          >
            <el-input v-model="form.provinces" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item
            label="备注"
            :label-width="formLabelWidth"
            prop="remark"
          >
            <el-input
              type="textarea"
              v-model="form.remark"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer" v-loading="formLoading">
        <el-button @click="reset('form')" v-show="!edit_id">重置</el-button>

        <el-button type="primary" @click="submit('form')">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="`跟进情况`"
      :visible.sync="followUpObj.visible"
      append-to-body
      width="70%"
      top="5vh"
    >
      <div class="dialogCenter">
        <ChangeableTable
          :key="followUpObj.loading"
          ref="changeableTable"
          :tableColumn="followUpObj.changeColumn"
          :loading="followUpObj.loading || followUpObj.submitLoading"
          :dataProps="followUpObj.tableData"
          :tableConfig="{
            stripe: true,
            defaultSort: { prop: 'date', order: null },
          }"
          :slotArray="slotArray"
          @save="situationSave"
        >
          <div slot="附件" slot-scope="{ scopeRow, index }" class="slotPart">
            <ChangeableTable
              @saveAll="
                saveAll(
                  $event,
                  scopeRow.id ? { id: scopeRow.id } : { index: index }
                )
              "
              :mapping="{ fileName: 'filePath' }"
              :tableColumn="uploadColumn"
              :addTitle="`添加附件`"
              :slotArray="['下载']"
              :dataProps="
                scopeRow.attachment ? JSON.parse(scopeRow.attachment) : []
              "
            >
              <div slot="下载" slot-scope="{ scopeRow }">
                <span v-show="!scopeRow.filePath"> 暂无下载</span>
                <el-link
                  v-show="scopeRow.filePath"
                  type="success"
                  :href="uploadUrl(scopeRow.filePath, scopeRow.fileName)"
                  >下载附件</el-link
                >
              </div>
            </ChangeableTable>
          </div>
        </ChangeableTable>
      </div>
    </el-dialog>

    <el-dialog
      :title="`附件`"
      :visible.sync="attachment.show"
      width="70%"
      top="10vh"
    >
      <div class="dialogCenter">
        <ChangeableTable
          :key="attachment.loading"
          ref="changeableTable"
          :tableColumn="attachment.column"
          :loading="attachment.loading || attachment.submitLoading"
          :dataProps="attachment.data"
          :tableConfig="{
            stripe: true,
          }"
          :addTitle="`添加附件`"
          :mapping="{ file_name: 'file_path' }"
          :slot-array="['下载']"
          @save="attachmentSaveFunc"
        >
          <div slot="下载" slot-scope="{ scopeRow }">
            <span v-show="!scopeRow.file_path"> 暂无下载</span>
            <el-link
              v-show="scopeRow.file_path"
              type="success"
              :href="uploadUrl(scopeRow.file_path, scopeRow.file_name)"
              >下载</el-link
            >
          </div>
        </ChangeableTable>
      </div>
    </el-dialog>
  </div>
</template>

<script>
const tableColumn = [
  // {
  //   dataIndex: "id",
  //   width: "100",
  //   title: "ID",
  //   returnField: "like-crm_linkman-id",
  // },
  {
    dataIndex: "name",
    width: "220",
    title: "联系人姓名",
    returnField: "like-crm_linkman-name",
  },
  {
    dataIndex: "company_name",
    width: "220",
    title: "公司名称",
    returnField: "like-crm_linkman-company_name",
  },
  {
    dataIndex: "division_name",
    width: "220",
    title: "所属部门",
    returnField: "like-chain-division_name",
  },
  {
    scopedSlots: "nickName",
    width: "220",
    title: "联系人所有人",
    // returnField: "like-admins-nickName",
    manyField: ["like-admins-nickName", "like-admins-realName"],
  },
  {
    dataIndex: "dutuies",
    width: "220",
    title: "职务",
    returnField: "like-crm_linkman-dutuies",
  },
  {
    dataIndex: "phone",
    width: "220",
    title: "固定电话",
    returnField: "like-crm_linkman-phone",
  },

  {
    dataIndex: "contact_number",
    width: "220",
    title: "联系电话",
    returnField: "like-crm_linkman-contact_number",
  },
  // {
  //   scopedSlots: "crm_customer_id",
  //   width: "220",
  //   title: "所属客户(id)",
  //   returnField: "like-crm_customer-id",
  // },
  // {
  //   scopedSlots: "customer_company_name",

  //   width: "220",
  //   title: "所属客户(公司名称)",
  //   returnField: "like-crm_customer-company_name",
  // },
  {
    scopedSlots: "sex",
    width: "220",
    title: "性别",
    dataType: "select",
    selectOptions: [
      {
        title: "男",
        value: 1,
      },
      {
        title: "女",
        value: 0,
      },
    ],
    returnField: "equal-crm_linkman-sex",
  },
  {
    dataIndex: "wechat_number",
    width: "220",
    title: "微信号",
    returnField: "like-crm_linkman-wechat_number",
  },
  {
    dataIndex: "email",
    width: "220",
    title: "邮件",
    returnField: "like-crm_linkman-email",
  },
  {
    dataIndex: "address",
    width: "220",
    title: "地址",
    returnField: "like-crm_linkman-address",
  },
  {
    dataIndex: "zipCode",
    width: "250",
    title: "邮编",
    returnField: "like-crm_linkman-zipCode",
  },
  {
    dataIndex: "provinces",
    width: "220",
    title: "省份",
    returnField: "like-crm_linkman-provinces",
  },
  {
    dataIndex: "remark",
    width: "250",
    title: "备注",
    returnField: "like-crm_linkman-remark",
  },
  {
    scopedSlots: "operation",
    width: "180",
    title: "操作",
    position: "right",
    noSearch: 1,
  },
  // { dataIndex: "remark", width: "250", title: "备注" },
];

const formOriginal = () => {
  return {
    name: null,
    company_name: null,
    dutuies: null,
    division_id: null,
    sex: null,
    admins_id: null,
    phone: null,
    wechat_number: null,
    email: null,
    address: null,
    zipCode: null,
    provinces: null,
    remark: null,
  };
};

const changeColumn = [
  {
    dataType: "date",
    title: "跟进日期",
    prop: "date",
    width: "250px",
    columnConfig: { sortable: true },
  },
  {
    dataType: "text",
    title: "跟进人",
    prop: "name",
    width: "200px",
  },
  {
    dataType: "text",
    title: "跟进状态",
    prop: "state",
    width: "120px",
  },
  {
    dataType: "textarea",
    title: "跟进描述",
    prop: "describe",
    width: "200px",
  },
];
const uploadColumn = [
  {
    dataType: "upload",
    title: "附件名称",
    prop: "fileName",
    width: "250px",
  },
  {
    dataType: "textarea",
    title: "附件备注",
    prop: "remark",
  },
];

const attachmentColumn = [
  {
    dataType: "upload",
    title: "附件名称",
    prop: "file_name",
    width: "250px",
  },
  {
    dataType: "textarea",
    title: "附件备注",
    prop: "remark",
  },
];

const phoneColumn = [
  {
    dataType: "text",
    title: "联系电话",
    prop: "text",
  },
];
const wechatColumn = [
  {
    dataType: "text",
    title: "微信号",
    prop: "text",
  },
];

import TreeSelct from "@/components/TreeSelct";
import TableGeneral from "@/components/TableGeneral";
import ChangeableTable from "@/components/ChangeableTable";
import { mapActions, mapState } from "vuex";
export default {
  name: "ComplexTable",
  components: {
    TreeSelct,
    TableGeneral,
    ChangeableTable,
  },
  props: {
    multiSelect: {
      type: Boolean,
      default: false,
    },
    linkmanSelList: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  authorize: {
    addShow: "添加",
    edit: "编辑",
    delOne: "删除",
    editObj: "编辑",
    followUp: "跟进情况",
  },
  data() {
    return {
      phoneColumn: phoneColumn,
      wechatColumn: wechatColumn,
      collapseValue: ["1", "2"],
      uploadColumn: uploadColumn,
      slotArray: ["附件"], //插槽名称
      dialogFormVisible: false,
      form: formOriginal(),
      formLabelWidth: "120px",
      treeDataLoading: true,
      tableLoading: true,
      formLoading: false,
      division_id: 0,
      treeData: [],
      edit_id: 0,
      linkmanBelong: {},
      config: {
        pageSize: 20,
        page: 1,
        keyWord: {},
      },
      rules: {
        name: [
          { required: true, message: "姓名不为空", trigger: "blur" },
          { max: 255, message: "长度不超过255字符", trigger: "blur" },
        ],
        company_name: [
          // { required: true, message: "公司名称不为空", trigger: "blur" },
          { max: 255, message: "长度不超过255字符", trigger: "blur" },
        ],
      },
      tableData: [],
      tableColumn: tableColumn,
      tableCount: 0,
      customer: {
        customersChoose: [],
        customerSelected: [],
        loading: false,
        customerLinkmanIdLoading: false,
      },
      phoneData: {
        loading: false,
        defaultData: [],
        length: 0,
        key: 0,
      },
      wechatData: {
        loading: false,
        defaultData: [],
        length: 0,
        key: 0,
      },
      followUpObj: {
        visible: false,
        changeColumn: changeColumn,
        loading: false,
        submitLoading: false,
        tableData: [],
        target_id: "", //联系人id
        followUp_id: "", //沟通记录表id
        table_name: "crm_linkman", //表名
      },
      attachment: {
        show: false,
        column: attachmentColumn,
        loading: false,
        data: [],
        submitLoading: false,
        clickMsg: {},
      },
    };
  },
  created() {
    this.divisionListLoad();
    this.linkmanListLoad();
    this.division_id = this.online_msg.division_id;
  },
  watch: {},
  computed: {
    ...mapState("user", ["online_msg"]),
  },

  methods: {
    ...mapActions("division", ["divisionList"]),
    ...mapActions("followUp", [
      "crmFollowUpAdd",
      "crmFollowUpEdit",
      "crmFollowUpSelOne",
    ]),
    ...mapActions("linkman", [
      "linkmanAdd",
      "linkmanEdit",
      "linkmanList",
      "linkmanSelOne",
      "attachmentList",
      "attachmentSave",
    ]),
    ...mapActions("customer", ["customerList", "customerLinkmanId"]),
    ...mapActions("situation", ["situationUpdateAdd", "situationList"]),
    closed() {
      this.edit_id = "";
      this.form = formOriginal();
      this.customer.customerSelected = []; //客户
      this.division_id = this.online_msg.division_id;
      this.phoneData.defaultData = [];
      this.phoneData.length = 0;
      this.wechatData.defaultData = [];
      this.wechatData.length = 0;
      this.wechatData.key++;
      this.phoneData.key++;
      this.collapseValue = ["1", "2"];

      this.$refs.treeSelct.reset();
      this.$refs.form.clearValidate();
    },
    addShow() {
      this.linkmanBelong = {
        nickName: this.online_msg.nickName,
        realName: this.online_msg.realName,
      };
      this.customerListLoad();
      this.dialogFormVisible = true;
    },
    reset(formName) {
      this.$refs[formName].resetFields();
      this.$refs.treeSelct.reset();
    },
    async linkmanListLoad() {
      this.tableLoading = true;
      let res = await this.linkmanList(this.config);
      if (res.code == 200) {
        const { list, total } = res.data;
        this.tableData = list;
        this.tableCount = total;
      }
      this.tableLoading = false;
    },
    search(e) {
      //  console.log(e)
      this.config.keyWord = e;
      this.linkmanListLoad();
    },
    async edit(scopeRow) {
      this.dialogFormVisible = true;
      this.formLoading = true;
      this.edit_id = scopeRow.id;
      this.customerListLoad();
      this.customerLinkmanIdLoad(scopeRow.id);
      let res = await this.linkmanSelOne({ id: scopeRow.id });
      if (res.code == 200) {
        Object.keys(this.form).forEach(
          (item) => (this.form[item] = res.data[item])
        );
        this.division_id = this.form.division_id;
        this.linkmanBelong = {
          nickName: scopeRow.nickName,
          realName: scopeRow.realName,
        };
        this.wechatData.defaultData = !res.data.wechat_number
          ? []
          : res.data.wechat_number.split(",").map((item) => {
              return { text: item };
            });
        this.wechatData.length = this.wechatData.defaultData.length;
        this.phoneData.defaultData = !res.data.contact_number
          ? []
          : res.data.contact_number.split(",").map((item) => {
              return { text: item };
            });
        this.phoneData.length = this.phoneData.defaultData.length;
        this.wechatData.key++;
        this.phoneData.key++;
        this.formLoading = false;
      }
    },
    async delOne(id) {
      this.tableLoading = true;
      let res = await this.linkmanEdit({
        formData: { delete_time: this.sysTime() },
        conditions: { id: id },
      });
      if (res.code == 200) {
        this.$message.success("删除成功");
      }
      this.linkmanListLoad();
    },
    async customerListLoad() {
      this.customer.loading = true;
      let res = await this.customerList();
      if (res.code == 200) {
        this.customer.customersChoose = res.data.list;
      }
      this.customer.loading = false;
    },
    ableSubmit() {
      let formData = {};
      this.$confirm("确定要修改吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        this.followUpObj.loading = true;
        formData.followUp = JSON.stringify(
          this.$refs.changeableTable.returnField()
        );
        let followUp_id = this.followUpObj.followUp_id;
        let res = followUp_id
          ? await this.crmFollowUpEdit({
              formData,
              conditions: { id: followUp_id },
            })
          : await this.crmFollowUpAdd({
              formData,
              target_id: this.followUpObj.target_id,
              tableName: "crm_linkman",
            });
        if (res.code == 200) {
          this.followUpObj.visible = false;
          this.$message.success("保存成功");
          this.linkmanListLoad();
        }
        this.followUpObj.loading = false;
      });
    },
    async followUp(id) {
      this.followUpObj.visible = true;
      this.followUpObj.loading = true;
      this.followUpObj.target_id = id;
      // if (scopeRow.followUp_id) {
      let res = await this.situationList({
        keyWord: {
          "equal-crm_situation-target_id": id,
          "equal-crm_situation-table_name": this.followUpObj.table_name,
        },
      });
      if (res.code == 200) {
        const { list } = res.data;
        this.followUpObj.tableData = list;
      }
      this.followUpObj.loading = false;
    },
    async attachmentFunc(row) {
      this.attachment.show = true;
      this.attachment.clickMsg = row;
      await this.attachmentListLoad({
        "equal-crm_linkman_attachment-linkman_id": row.id,
      });
    },
    async attachmentListLoad(keyWord) {
      this.attachment.loading = true;
      let res = await this.attachmentList({ keyWord });
      if (res.code == 200) {
        this.attachment.data = res.data.list;
      }
      this.attachment.loading = false;
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm(
            "确定要" + (this.edit_id ? "编辑" : "添加") + "吗?",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          )
            .then(async () => {
              this.formLoading = true;

              let form = this.form;
              form.division_id = this.$refs.treeSelct.valueId;
              form.admins_id = this.online_msg.id;
              form.wechat_number = this.$refs.wechat.tableData
                .map((item) => item.text)
                .join(",");
              form.contact_number = this.$refs.phone.tableData
                .map((item) => item.text)
                .join(",");
              if (this.edit_id) {
                delete form.admins_id;
                var res = await this.linkmanEdit({
                  formData: form,
                  conditions: { id: this.edit_id },
                  customer_id: this.customer.customerSelected,
                });
              } else {
                var res = await this.linkmanAdd({
                  formData: form,
                  customer_id: this.customer.customerSelected,
                });
              }
              if (res.code == 200) {
                this.$message.success(res.message);
                this.dialogFormVisible = false;
                this.linkmanListLoad();
                if (this.multiSelect && this.edit_id) {
                  //修改并且是多选页面
                  // console.log(111)
                  // console.log(this.$refs.TableGeneral)
                  // console.log(this.$refs.tableGeneral.updateChecked(form,this.edit_id))
                  //  this.$refs.TableGeneral.updateChecked(form, this.edit_id)
                  this.$emit("editChecked", this.$refs.tableGeneral.checkList);
                }
              }
              this.formLoading = false;
            })

            .catch(() => {});
        } else {
          // console.log('error submit!!');
          this.$message.error("信息填写错误");
          return false;
        }
      });
    },
    currentChange(e) {
      this.config.page = e;
      this.linkmanListLoad();
    },
    sizeChange(e) {
      this.config.pageSize = e;
      this.linkmanListLoad();
    },
    async divisionListLoad() {
      this.treeDataLoading = true;
      let res = await this.divisionList({ "equal-crm_division-status": 1 });
      if (res.code == 200) {
        // this.treeData[0] = { name: "全公司", id: 0, children: [] };
        this.treeData = res.data.list;
        this.treeDataLoading = false;
      }
    },
    returnSelArray() {
      return this.$refs.tableGeneral.checkList;
    },
    async situationSave(formData, index) {
      this.followUpObj.submitLoading = true;
      formData["table_name"] = this.followUpObj.table_name;
      formData["target_id"] = this.followUpObj.target_id;
      let res = await this.situationUpdateAdd({ formData });
      if (res.code == 200) {
        this.$message({
          message: formData.hasOwnProperty("delete_time")
            ? "删除成功"
            : "保存成功",
          type: "success",
        });
        if (res.data.id) {
          this.$refs.changeableTable.assignment(index, { id: res.data.id });
        }
      }
      this.followUpObj.submitLoading = false;
    },
    async attachmentSaveFunc(row) {
      this.attachment.submitLoading = true;
      row.linkman_id = this.attachment.clickMsg.id;
      let res = await this.attachmentSave({ formData: row });
      if (res.code == 200) {
        if (row.hasOwnProperty("delete_time")) {
          this.$message.success("删除成功");
        } else {
          this.$message.success("保存成功");
        }
      }
      this.attachment.submitLoading = false;
    },
    async customerLinkmanIdLoad(linkman_id) {
      this.customer.customerLinkmanIdLoading = true;
      let res = await this.customerLinkmanId({ linkman_id });
      if (res.code == 200 && res.data) {
        this.customer.customerSelected = res.data;
      }
      this.customer.customerLinkmanIdLoading = false;
    },
    async saveAll(data, obj) {
      this.followUpObj.submitLoading = true;
      let dataJson = JSON.stringify(data);
      if (obj.hasOwnProperty("id")) {
        var res = await this.situationUpdateAdd({
          formData: { attachment: dataJson, id: obj.id },
        });
        if (res.code == 200) {
          this.$message.success("保存成功");
        }
      } else if (obj.hasOwnProperty("index")) {
        this.$refs.changeableTable.assignment(obj.index, {
          attachment: dataJson,
        });
      }
      this.followUpObj.submitLoading = false;
    },
  },
};
</script>
<style scoped lang="less">
.dialogCenter {
  height: 70vh;
  overflow-y: scroll;
  padding: 10px;
}
.pagination {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 30px;
}
</style>
